from selenium.webdriver.support.ui import WebDriverWait
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
class Base():
    def __init__(self,driver):
        self.driver = driver
    def open_url(self,url):
        self.driver.get(url)
    def error_png(self):
        apng = time.strftime("%Y%m%d-%H%M%S")
        return apng
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc)).is_displayed()
            return self.driver.find_element(*loc)
        except Exception as e:
            self.driver.save_screenshot('a.png')
            print(e)
    def send_keys(self,loc,info):
        self.find_element(loc).send_keys(info)
    def click(self,loc):
        self.find_element(loc).click()
    def Keys(self,loc):
        self.find_element(loc).send_key(Keys.ENTER)
    def shu(self,loc):
        ActionChains(self.driver).click(self.find_element(loc)).perform()
    def windowSwitching(self):
        self.driver.switch_to.window(self.driver.window_handles[-1])
    def new_winow(self,x):
        self.driver.execute_script(f'window.scrollTo(0,{x})')
    def new_windsow(self):
        self.driver.execute_script('window.scrollTo(0,document.bodyw.scrollHeight)')
